/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TransaksiPenjualanLain.java
 *
 * Created on Aug 11, 2010, 11:28:41 PM
 */
package com.ivanbiz.gui;

import com.ivanbiz.helper.RightRenderer;
import com.ivanbiz.dao.BarangDAO;
import com.ivanbiz.dao.NotaDAO;
import com.ivanbiz.helper.CenterRenderer;
import com.ivanbiz.helper.RandomList;
import com.ivanbiz.helper.ServiceHelper;
import com.ivanbiz.impl.BarangDAOImpl;
import com.ivanbiz.impl.NotaDAOImpl;
import com.ivanbiz.model.Barang;
import com.ivanbiz.model.ItemNotaLain;
import com.ivanbiz.model.NotaLain;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;

/**
 *
 * @author Aprisma
 */
public class TransaksiPenjualanLain extends javax.swing.JInternalFrame {

    ServiceHelper serviceHelper = new ServiceHelper();
    NotaDAO notaDAO = new NotaDAOImpl();
    BarangDAO barangDAO = new BarangDAOImpl();
    List<ItemNotaLain> listItemNotaLain = new ArrayList<ItemNotaLain>();
    List<Barang> listBarang = new ArrayList<Barang>();
    NumberFormat numberFormat = NumberFormat.getInstance(Locale.US);
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd MMMM yyyy");
    SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("MMyy");

    /** Creates new form TransaksiPenjualan */
    public TransaksiPenjualanLain() {
        initComponents();
        updateData();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        groupPilihan = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        labelTanggal = new javax.swing.JLabel();
        textTanggal = new javax.swing.JTextField();
        labelKode = new javax.swing.JLabel();
        textKode = new javax.swing.JTextField();
        labelKeterangan = new javax.swing.JLabel();
        textKeterangan = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        buttonProses = new javax.swing.JButton();
        textTotal = new javax.swing.JTextField();
        labelPT = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tableItemNota = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        comboBarang = new javax.swing.JComboBox();
        textHargaJual = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        buttonTambah = new javax.swing.JButton();
        buttonKurang = new javax.swing.JButton();
        textCari = new javax.swing.JTextField();
        comboCari = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();

        setBorder(new org.jdesktop.swingx.border.DropShadowBorder());
        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setTitle("Transaksi Penjualan Lain - Lain");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Penjualan Lain - Lain"));

        labelTanggal.setFont(new java.awt.Font("Tahoma", 1, 11));
        labelTanggal.setText("Tanggal");

        textTanggal.setEditable(false);
        textTanggal.setFont(new java.awt.Font("Tahoma", 1, 11));
        textTanggal.setText("jTextField1");

        labelKode.setFont(new java.awt.Font("Tahoma", 1, 11));
        labelKode.setText("Kode");

        textKode.setEditable(false);
        textKode.setFont(new java.awt.Font("Tahoma", 1, 11));
        textKode.setText("jTextField2");

        labelKeterangan.setFont(new java.awt.Font("Tahoma", 1, 11));
        labelKeterangan.setText("Keterangan");

        textKeterangan.setFont(new java.awt.Font("Tahoma", 1, 11));
        textKeterangan.setText("jTextField1");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelTanggal)
                    .addComponent(labelKode)
                    .addComponent(labelKeterangan))
                .addGap(8, 8, 8)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(textTanggal, javax.swing.GroupLayout.DEFAULT_SIZE, 240, Short.MAX_VALUE)
                    .addComponent(textKeterangan, javax.swing.GroupLayout.DEFAULT_SIZE, 240, Short.MAX_VALUE)
                    .addComponent(textKode, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 240, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelTanggal)
                    .addComponent(textTanggal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textKode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelKode))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textKeterangan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelKeterangan))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Total"));

        buttonProses.setFont(new java.awt.Font("Tahoma", 1, 11));
        buttonProses.setText("Prosess");
        buttonProses.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonProsesActionPerformed(evt);
            }
        });

        textTotal.setEditable(false);
        textTotal.setFont(new java.awt.Font("Tahoma", 1, 18));
        textTotal.setText("jTextField2");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(textTotal, javax.swing.GroupLayout.DEFAULT_SIZE, 653, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(buttonProses)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(buttonProses, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(textTotal, javax.swing.GroupLayout.Alignment.LEADING))
                .addContainerGap(12, Short.MAX_VALUE))
        );

        labelPT.setFont(new java.awt.Font("Tahoma", 1, 36));
        labelPT.setText("PT BERGUNA JAYA");

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Tabel Penjualan Lain - Lain"));

        tableItemNota.setAutoCreateRowSorter(true);
        tableItemNota.setFont(new java.awt.Font("Tahoma", 1, 11));
        tableItemNota.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(tableItemNota);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel1.setText("Barang");

        comboBarang.setFont(new java.awt.Font("Tahoma", 1, 11));
        comboBarang.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        textHargaJual.setFont(new java.awt.Font("Tahoma", 1, 11));
        textHargaJual.setText("jTextField1");

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel2.setText("Harga Jual");

        buttonTambah.setFont(new java.awt.Font("Tahoma", 1, 11));
        buttonTambah.setText("+");
        buttonTambah.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonTambahActionPerformed(evt);
            }
        });

        buttonKurang.setFont(new java.awt.Font("Tahoma", 1, 11));
        buttonKurang.setText("-");
        buttonKurang.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonKurangActionPerformed(evt);
            }
        });

        textCari.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        textCari.setText("jTextField1");
        textCari.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                textCariKeyReleased(evt);
            }
        });

        comboCari.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        comboCari.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 742, Short.MAX_VALUE)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(29, 29, 29)
                        .addComponent(comboBarang, 0, 359, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(textHargaJual, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(buttonTambah)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(buttonKurang))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addComponent(comboCari, 0, 164, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(textCari, javax.swing.GroupLayout.PREFERRED_SIZE, 572, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textCari, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(comboCari, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(comboBarang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addComponent(buttonKurang)
                    .addComponent(buttonTambah)
                    .addComponent(textHargaJual, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE)
                .addContainerGap())
        );

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel4.setText("Jln. Jembatan Selatan no 470 Panglima Polim Jakarta Selatan ");

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel5.setText("Telp : 08174820800");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(labelPT)
                            .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(labelPT)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel5))
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-800)/2, (screenSize.height-550)/2, 800, 550);
    }// </editor-fold>//GEN-END:initComponents

    private void buttonTambahActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonTambahActionPerformed
        try {
            Barang barang = (Barang) listBarang.get(comboBarang.getSelectedIndex());
            if (textHargaJual.getText().isEmpty()) {
                JOptionPane.showMessageDialog(null, "Harga Jual Belum diisi !!!");
            } else {
                ItemNotaLain itemNotaLain = new ItemNotaLain();
                itemNotaLain.setBarang(barang);
                itemNotaLain.setHargaJual(Double.parseDouble(textHargaJual.getText()));
                itemNotaLain.setCreateDate(ServiceHelper.getDateNow());
                itemNotaLain.setNote(textKeterangan.getText().toUpperCase());
                boolean cek = true;
                for (int x = 0; x < listItemNotaLain.size(); x++) {
                    ItemNotaLain itemNotaLainTemporary = (ItemNotaLain) listItemNotaLain.get(x);
                    if (barang.getId() == itemNotaLainTemporary.getBarang().getId()) {
                        cek = false;
                        JOptionPane.showMessageDialog(null, "Barang Sudah Dipilih !!! ");
                    }
                }
                if (cek == true) {
                    listItemNotaLain.add(itemNotaLain);
                    updateTableItemNota();
                    updateTotal();
                    textHargaJual.setText("");
                }
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Format Harga Harus Angka !!!");
            Logger.getLogger(TransaksiPenjualanLain.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_buttonTambahActionPerformed

    private void buttonKurangActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonKurangActionPerformed
        listItemNotaLain.remove(tableItemNota.getSelectedRow());
        updateTableItemNota();
        updateTotal();
    }//GEN-LAST:event_buttonKurangActionPerformed

    private void buttonProsesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonProsesActionPerformed
        try {
            NotaLain notaLain = new NotaLain();
            notaLain.setKode(textKode.getText().toUpperCase());
            notaLain.setNote(textKeterangan.getText().toUpperCase());
            notaLain.setCreateDate(ServiceHelper.getDateNow());
            notaLain.setItemNota(listItemNotaLain);
            if (notaLain.getNote().isEmpty()) {
                JOptionPane.showMessageDialog(null, "Keterangan Kosong !!!");
            } else if (notaLain.getItemNota().isEmpty()) {
                JOptionPane.showMessageDialog(null, "Barang Kosong !!!");
            } else {
                notaDAO.save(notaLain);
                listItemNotaLain.clear();
                updateData();
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Error Data Tidak Masuk");
            Logger.getLogger(TransaksiPenjualanLain.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_buttonProsesActionPerformed

    private void textCariKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textCariKeyReleased
        try {
            listBarang = barangDAO.getDataByLike(Barang.class, comboCari.getSelectedItem().toString(), textCari.getText());
            updateComboBarang();
        } catch (Exception ex) {
            Logger.getLogger(TransaksiPenjualanLain.class.getName()).log(Level.SEVERE, null, ex);
        }
}//GEN-LAST:event_textCariKeyReleased

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonKurang;
    private javax.swing.JButton buttonProses;
    private javax.swing.JButton buttonTambah;
    private javax.swing.JComboBox comboBarang;
    private javax.swing.JComboBox comboCari;
    private javax.swing.ButtonGroup groupPilihan;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel labelKeterangan;
    private javax.swing.JLabel labelKode;
    private javax.swing.JLabel labelPT;
    private javax.swing.JLabel labelTanggal;
    private javax.swing.JTable tableItemNota;
    private javax.swing.JTextField textCari;
    private javax.swing.JTextField textHargaJual;
    private javax.swing.JTextField textKeterangan;
    private javax.swing.JTextField textKode;
    private javax.swing.JTextField textTanggal;
    private javax.swing.JTextField textTotal;
    // End of variables declaration//GEN-END:variables

    private void updateComboBarang() {
        Object data[] = new Object[listBarang.size()];
        int x = 0;
        for (Barang barang : listBarang) {
            data[x] = barang.getKode() + " (" + barang.getNama() + " Rp " + numberFormat.format(barang.getHarga()) + ",00" + ")" + " stock " + barang.getStock() + " / " + barang.getSatuan().getNama();
            x++;
        }
        comboBarang.setModel(new DefaultComboBoxModel(data));
    }

    private void updateComboBarangByFind(String nama) {
        Iterator iter = this.listBarang.iterator();
        while (iter.hasNext()) {
            Barang barang = (Barang) iter.next();
            if (!barang.getNama().startsWith(nama)) {
                iter.remove();
            }
        }
        Object data[] = new Object[listBarang.size()];
        int x = 0;
        for (Barang barang : listBarang) {
            data[x] = barang.getKode() + " (" + barang.getNama() + " Rp " + numberFormat.format(barang.getHarga()) + ",00" + ")" + " stock " + barang.getStock() + " / " + barang.getSatuan().getNama();
            x++;
        }
        comboBarang.setModel(new DefaultComboBoxModel(data));
    }

    private void updateComboCari() {
        Object[] dataClass = serviceHelper.getPropertyClass(Barang.class);
        Object[] dataSearch = new Object[3];
        dataSearch[0] = dataClass[1];
        dataSearch[1] = dataClass[2];
        dataSearch[2] = dataClass[6];
        comboCari.setModel(new DefaultComboBoxModel(dataSearch));
    }
    // End of variables declaration

    private void updateData() {
        try {
            Date date = new Date();
            RandomList randomList = new RandomList();
            textCari.setText("");
            textTanggal.setText(simpleDateFormat.format(new Date()));
            textHargaJual.setText("");
            textTotal.setText("");
            textKeterangan.setText("");
            textKode.setText("L" + simpleDateFormat1.format(date) + randomList.getGeneratePassword());
            updateTableItemNota();
            updateTotal();
            listBarang = barangDAO.getAll(Barang.class);
            updateComboBarang();
            updateComboCari();
        } catch (Exception ex) {
            Logger.getLogger(TransaksiPenjualanLain.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void updateTableItemNota() {
        String[] judul = {"No", "Kode", "Nama", "Satuan", "Harga"};
        Object[][] isi = new Object[listItemNotaLain.size()][5];
        int x = 0;
        int no = 0;
        for (ItemNotaLain itemNotaLain : listItemNotaLain) {
            isi[x][0] = no += 1;
            isi[x][1] = itemNotaLain.getBarang().getKode();
            isi[x][2] = itemNotaLain.getBarang().getNama();
            isi[x][3] = itemNotaLain.getBarang().getSatuan().getNama();
            isi[x][4] = "Rp " + numberFormat.format(itemNotaLain.getHargaJual()) + ",00";
            x++;
        }
        tableItemNota.setModel(new DefaultTableModel(isi, judul) {

            @Override
            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return false;
            }
        });
        TableColumn column0 = tableItemNota.getColumnModel().getColumn(0);
        column0.setPreferredWidth(50);
        column0.setMaxWidth(50);
        column0.setCellRenderer(new CenterRenderer());
        TableColumn column1 = tableItemNota.getColumnModel().getColumn(1);
//        column1.setPreferredWidth(100);
//        column1.setMaxWidth(100);
        column1.setCellRenderer(new CenterRenderer());
        TableColumn column3 = tableItemNota.getColumnModel().getColumn(3);
//        column3.setPreferredWidth(140);
//        column3.setMaxWidth(140);
        column3.setCellRenderer(new CenterRenderer());
        TableColumn column4 = tableItemNota.getColumnModel().getColumn(4);
//        column4.setPreferredWidth(140);
//        column4.setMaxWidth(140);
        column4.setCellRenderer(new RightRenderer());
    }

    private void updateTotal() {
        double total = 0;
        for (ItemNotaLain itemNotaLain : listItemNotaLain) {
            total += itemNotaLain.getHargaJual();
        }
        textTotal.setText("Rp " + numberFormat.format(total) + ",00");
    }
}
